package poker;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;


public class Logger {
	private static Logger instance;
	private static GameRound gameRound;
	private static StringBuilder log;
	private static int num;
	
	private Logger() 
	{
		log = new StringBuilder();
		num = 0;
	}
		
	/**
	 * Singleton
	 * @return
	 */
	public static Logger getInstance() 
	{
		if(instance == null)
			instance = new Logger();
		
		return instance;
	}
	
	public void Log(String text)
	{
		log.append(text);
	}
	
	public void reset()
	{
		log = new StringBuilder();
	}
	
	public void Save()
	{  
		try
		{
			DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
			Date date = new Date();
			File file = new File("logs/poker-" + dateFormat.format(date) + num + ".log");
			PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(file)));
			writer.write(log.toString());
			writer.close();
			num++;
		}
		catch(IOException e)
		{
			System.err.println("Could not write to log");
			e.printStackTrace();
		}
	}
}
